//
//  PhotoScrollView.m
//  项目1 CLCMovie
//
//  Created by huiwenjiaoyu on 15/7/23.
//  Copyright (c) 2015年 CLC. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation PhotoScrollView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor blackColor];
        imgV = [[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:imgV];
        [imgV setBackgroundColor:[UIColor whiteColor]];
        self.delegate = self;
        self.maximumZoomScale = 3;
        self.minimumZoomScale = 1;

        
        //添加双击缩放手势
        UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        //添加单击隐藏NavigationBar手势
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
        
        singleTap.numberOfTapsRequired = 1;
        singleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:singleTap];
        
    }
    
    return self;
}


#pragma mark - 双击事件/单击事件
- (void)doubleTap
{
    if (self.zoomScale == 1)
        [self setZoomScale:3 animated:YES];
    else
        [self setZoomScale:1 animated:YES];
}

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imgV;
}

- (void)singleTap
{
    NSLog(@"1");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HideNavigationBarNotification" object:nil];
}
#pragma mark － 数据传递与布局
- (void)setImageURL:(NSString *)imageURL
{
    _imageURL = imageURL;
    [self setNeedsLayout];
}


- (void)layoutSubviews
{
    NSURL* url = [NSURL URLWithString:_imageURL];
    
    
    [imgV sd_setImageWithURL:url];
    [imgV setContentMode:UIViewContentModeScaleAspectFit];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
